package com.cskaoyan.controller;

import com.cskaoyan.bean.*;
import com.cskaoyan.bean.bo.*;
import com.cskaoyan.bean.vo.*;
import com.cskaoyan.service.MarketService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
public class MarketController {
   @Autowired
    MarketService marketService;

    @RequestMapping("admin/region/list")
    //获取行政区
    public BaseRespVo serverList() {
        //调用selectProvinces方法，得到全部的数据
        List<ProvinceVo> provinces = marketService.selectProvinces();
//        将全部的数据封装进BaseRespVo，符合前端接受的json字符串
        return BaseRespVo.success(provinces);
    }
    //获取品牌商分页查询
    @RequiresPermissions("admin:brand:list")
    @RequestMapping("admin/brand/list")
    public BaseRespVo selectAllBrand(AllBrandBo allBrandBo) {
        //调用mapper 的方法，获得对应的Javabean
       AllBrandVo allBrandVo= marketService.allBrandService(allBrandBo);
       // 将全部的数据封装进BaseRespVo，符合前端接受的json字符串
        return BaseRespVo.success(allBrandVo);
    }
    //上传图片
    @RequiresPermissions("admin:storage:create")
    @RequestMapping("admin/storage/create" )
    public BaseRespVo addCreate( MultipartFile file) {
        StorageVo addCreateVo = marketService.addCreateService(file);
        return BaseRespVo.success(addCreateVo);
    }

    @RequiresPermissions("admin:brand:create")
    @RequestMapping("admin/brand/create")
    //添加品牌
    public BaseRespVo addBrand(@RequestBody BrandBVo brandBVo) {
        BrandBVo addBrandVo =  marketService.addBrandService(brandBVo);
        return BaseRespVo.success(addBrandVo);
    }

    @RequiresPermissions("admin:brand:update")
    @RequestMapping("admin/brand/update")
    //修改品牌商信息
    public BaseRespVo updateBrand(@RequestBody CskaoyanmallBrand brandBVo) {
       CskaoyanmallBrand updateBrandVo =  marketService.updateBrandService(brandBVo);
        return BaseRespVo.success(updateBrandVo);
    }

    @RequiresPermissions("admin:brand:delete")
    @RequestMapping("admin/brand/delete")//删除商品信息
    public BaseRespVo deleteBrand(@RequestBody CskaoyanmallBrand brandB) {

        Integer i = marketService.deleteBrand(brandB);
        return BaseRespVo.success();
    }

    @RequiresPermissions("admin:category:list")
    @RequestMapping("admin/category/list")
    //商品类目list
    public BaseRespVo categoryList() {
        List<CategoryList> categoryList=marketService.categoryListService();
        return BaseRespVo.success(categoryList);
    }

    @RequiresPermissions("admin:category:list")
    @RequestMapping("admin/category/l1")
    public BaseRespVo categoryListL1() {
        List<CategoryL1Vo> categoryL1VoList =  marketService.categoryListL1Service();
        return BaseRespVo.success(categoryL1VoList);
    }

    @RequiresPermissions("admin:category:create")
    @RequestMapping("admin/category/create")
    public BaseRespVo categoryCreate(@RequestBody()CskaoyanmallCategory category) {
        CskaoyanmallCategory createVo = marketService.categoryCreateService(category);
        return BaseRespVo.success(createVo);
    }

    @RequiresPermissions("admin:category:update")
    @RequestMapping("admin/category/update")
    //编辑商品类目
    public BaseRespVo categoryUpdate(@RequestBody CskaoyanmallCategory category) {
        Integer integer = marketService.categoryUpdateService(category);
        return BaseRespVo.success();
    }

    @RequiresPermissions("admin:category:delete")
    @RequestMapping("admin/category/delete")
    //删除商品类目
    public BaseRespVo categoryDelete(@RequestBody CategoryList categoryList) {
        Integer i =marketService.categoryDeleteService(categoryList);
        return BaseRespVo.success();
    }

    @RequiresPermissions("admin:order:list")
    @RequestMapping("admin/order/list")
    //订单页面

    public BaseRespVo orderList( OrderListBo orderBo) {

      OrderListVo orderListVo = marketService.orderListService(orderBo);
        return BaseRespVo.success(orderListVo);
    }


    @RequiresPermissions("admin:order:detail")
    @RequestMapping("admin/order/detail")
    public BaseRespVo orderDetail(Integer id) {
        OrderDetailVo orderDetailVo =marketService.orderDetailService(id);
        return BaseRespVo.success(orderDetailVo);
    }

    @RequiresPermissions("admin:order:refund")
    @RequestMapping("admin/order/refund")
    //没有支付页面，只能返回退款失败
    public BaseRespVo orderRefund(@RequestBody OrderRefundBo bo) {
        Integer i=marketService.orderRefundService(bo);
        BaseRespVo baseRespVo = new BaseRespVo();
        baseRespVo.setErrmsg("订单退款失败");
        baseRespVo.setErrno(621);
        return baseRespVo;
    }

    @RequiresPermissions("admin:order:ship")
    @RequestMapping("admin/order/ship")//发货
    public BaseRespVo orderShip(@RequestBody OrderShipBo bo) {
        Integer i =marketService.OrderShipService(bo);
        return BaseRespVo.success();
    }

    @RequiresPermissions("admin:issue:list")
    @RequestMapping("admin/issue/list")
    public BaseRespVo issueList( IssueListBo bo) {
        IssueListVo issueListVo = marketService.issueListService(bo);
        return BaseRespVo.success(issueListVo);
    }

    @RequiresPermissions("admin:issue:create")
    @RequestMapping("admin/issue/create")
    //添加问题
    public BaseRespVo issueCreate(@RequestBody CskaoyanmallIssue bo) {
        CskaoyanmallIssue issueVo = marketService.issueCreateService(bo);
        return BaseRespVo.success(issueVo);
    }

    @RequiresPermissions("admin:issue:update")
    @RequestMapping("admin/issue/update")
    //修改问题
    public BaseRespVo issueUpdate(@RequestBody CskaoyanmallIssue bo) {
        CskaoyanmallIssue issueVo = marketService.issueUpdateService(bo);
        return BaseRespVo.success(issueVo);
    }

    @RequiresPermissions("admin:issue:delete")
    @RequestMapping("admin/issue/delete")
    //问题删除
    public BaseRespVo issueDelete(@RequestBody CskaoyanmallIssue bo) {
        Integer i = marketService.issueDeleteService(bo);
        return BaseRespVo.success();

    }

    @RequiresPermissions("admin:keyword:list")
    @RequestMapping("admin/keyword/list")
    //关键词查询
    public BaseRespVo keywordList( KeywordListBo bo) {
        KeywordListVo keywordListVo= marketService.keywordListService(bo);
        return BaseRespVo.success(keywordListVo);
    }

    @RequiresPermissions("admin:keyword:create")
    @RequestMapping("admin/keyword/create")
    //添加关键词
    public BaseRespVo keywordCreate (@RequestBody CskaoyanmallKeyword bo) {
        CskaoyanmallKeyword keywordVo = marketService.keywordCreateService(bo);
        return BaseRespVo.success(keywordVo);
    }

    @RequiresPermissions("admin:keyword:delete")
    @RequestMapping("admin/keyword/delete")
    public BaseRespVo keywordDelete(@RequestBody CskaoyanmallKeyword bo) {
        Integer i = marketService.keywordDeleteService(bo);

        return BaseRespVo.success();
    }
    @RequiresPermissions("admin:keyword:update")
    @RequestMapping("admin/keyword/update")
    public BaseRespVo keywordUpdate(@RequestBody CskaoyanmallKeyword bo) {
        CskaoyanmallKeyword keyword = marketService.keywordUpdateService(bo);
        return BaseRespVo.success(keyword);

    }
}
